package cn.openea.perpartner.meily.web.entity.dto;

import cn.openea.perpartner.common.core.annotation.Excel;
import cn.openea.perpartner.meily.web.entity.ProvideSamplesSub;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Component;

import java.util.function.Function;

/**
 * @author rains
 * @since 2023-04-18 12:06
 */
@Component
public class ProvideSamplesSubDTOFactory {

    @Data
    @AllArgsConstructor
    @NoArgsConstructor
    @SuperBuilder
    public static class ExportDTO {
        @Excel(name = "用户ID")
        private String partnerId;
        @Excel(name = "用户昵称")
        private String partnerName;
        @Excel(name = "报名时间")
        private String createTime;
        @Excel(name = "订单状态")
        private String orderStatus;
        @Excel(name = "收货人姓名")
        private String consigneeName;
        @Excel(name = "手机号码")
        private String consigneePhoneNum;
        @Excel(name = "收货地址")
        private String consigneeAddress;
        @Excel(name = "备注")
        private String orderRemarks;
        @Excel(name = "物流信息")
        private String logisticsInfo;
    }

    public Function<ProvideSamplesSub, ProvideSamplesSubDTOFactory.ExportDTO> toExportDTO = (provideSamplesSub) -> {
        if (provideSamplesSub == null) {
            return null;
        }
        ProvideSamplesSubDTOFactory.ExportDTO exportDTO = new ProvideSamplesSubDTOFactory.ExportDTO();
        BeanUtils.copyProperties(provideSamplesSub, exportDTO);
        // 物流信息 = 物流公司名称 + 物流单号
        exportDTO.setLogisticsInfo(provideSamplesSub.getCourierName() + " " + provideSamplesSub.getCourierNumber());
        return exportDTO;
    };

    /**
     * 样品发货模板
     */
    @Data
    @AllArgsConstructor
    @NoArgsConstructor
    @SuperBuilder
    public static class SamplesShipmentTemplateDTO {
        @Excel(name = "样品编号")
        private String id;
        @Excel(name = "用户ID")
        private String partnerId;
        @Excel(name = "用户昵称")
        private String partnerName;
        @Excel(name = "报名时间")
        private String createTime;
        @Excel(name = "收货人姓名")
        private String consigneeName;
        @Excel(name = "手机号码")
        private String consigneePhoneNum;
        @Excel(name = "收货地址")
        private String consigneeAddress;
        @Excel(name = "备注")
        private String orderRemarks;
        @Excel(name = "物流公司名称")
        private String courierName;
        @Excel(name = "物流单号")
        private String courierNumber;
    }

    public Function<ProvideSamplesSub, SamplesShipmentTemplateDTO> toSamplesShipmentTemplateDTO = (provideSamplesSub) -> {
        if (provideSamplesSub == null) {
            return null;
        }
        SamplesShipmentTemplateDTO shipmentTemplateDTO = new SamplesShipmentTemplateDTO();
        BeanUtils.copyProperties(provideSamplesSub, shipmentTemplateDTO);
        return shipmentTemplateDTO;
    };

    /**
     * 评价DTO
     */
    @Data
    @AllArgsConstructor
    @NoArgsConstructor
    @SuperBuilder
    public static class ExportEvaluationDTO {
        @Excel(name = "用户ID")
        private String partnerId;
        @Excel(name = "用户昵称")
        private String partnerName;
        @Excel(name = "报名时间")
        private String createTime;
        @Excel(name = "订单状态")
        private String orderStatus;
        @Excel(name = "手机号码")
        private String consigneePhoneNum;
        @Excel(name = "试用反馈")
        private String  feedbackContent;
    }

    public Function<ProvideSamplesSub, ExportEvaluationDTO> toExportEvaluationDTO = (provideSamplesSub) -> {
        if (provideSamplesSub == null) {
            return null;
        }
        ExportEvaluationDTO exportEvaluationDTO = new ExportEvaluationDTO();
        BeanUtils.copyProperties(provideSamplesSub, exportEvaluationDTO);
        return exportEvaluationDTO;
    };
}
